from web.BlackWidow.BaiDu.BlackWidow import BlackWidow_BaiDu

from django.http import JsonResponse

# 百度翻译之黑寡妇版
black_widow_bai_du = BlackWidow_BaiDu()

# 获取语种
def get_language(request):
    text = request.GET.get('query')
    language = black_widow_bai_du.get_translate_language(text)
    return JsonResponse(language)

# 获取翻译文本相似的文本
def get_sug_text(request):
    text = request.GET.get('query')
    sug_text = black_widow_bai_du.get_sug_text(text)
    return JsonResponse(sug_text)

# 翻译
def translate(request):
    text = request.GET.get('query')
    from_lang = request.GET.get('from_lang', 'zh')
    to_lang = request.GET.get('to_lang', 'en')
    translate = black_widow_bai_du.translate(text, from_lang, to_lang)
    return JsonResponse(translate, safe=False)

